/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gwt.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import gwt.client.Proveedor;
import gwt.client.ServicioProveedor;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Ricardo Armando Machorro Reyes
 */
public class ServicioProveedorImpl extends RemoteServiceServlet implements ServicioProveedor {
    
    private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("proveedores");

    @Override
    public void agrega(Proveedor objeto) {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            em.persist(objeto);
            tx.commit();
        } finally {
            
            if (tx.isActive()){
                tx.rollback();
            
            }
            em.close();
        }
        
    }

    @Override
    public Proveedor todos(Long clave) {
        EntityManager em = emf.createEntityManager();
        
        try {
            Proveedor objeto = em.find(Proveedor.class, clave);
            return objeto;
        } finally {
            
            em.close();
        }
    }

   
}
